# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=pygit2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.12.2
pkgrel=2
pkgdesc='Python bindings for libgit2 (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://github.com/libgit2/pygit2'
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-libgit2"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cffi")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "libgit2-1.7.patch")
sha256sums=('56e85d0e66de957d599d1efb2409d39afeefd8f01009bfda0796b42a4b678358'
            'fb1023efd7cbdc804502e5d1dc62ecac15bcce85d44c6cb3b5a847ac3737d73f')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  cd "${srcdir}/python-build-${MSYSTEM}"

  # https://github.com/libgit2/pygit2/issues/1231
  # https://gitlab.archlinux.org/archlinux/packaging/packages/python-pygit2/-/blob/main/libgit2-1.7.patch
  patch -p1 -i "${srcdir}/libgit2-1.7.patch"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
